package com.shujujiegou;

/**
 * Created by Administrator on 2018/5/23/023.
 */
public class TestDeadLock {

    public static void main(String[] args) {
        final Object obj1 = new Object();
        final Object obj2 = new Object();
        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj1) {
                    System.out.println("获取锁1等待执行.....");
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (obj2) {
                        System.out.println("获取锁2等待执行.....");
                    }
                }
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj2) {
                    System.out.println("获取锁2等待执行.....");
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (obj1) {
                        System.out.println("获取锁1等待执行.....");
                    }
                }
            }
        }).start();
    }


}
